a11y: Validate the DBus context path
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 9 Oct 2020 21:33:51 +0000 (22:33 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 12 Oct 2020 15:19:32 +0000 (16:19 +0100)
UUIDs use dashes to separate the various blocks; unfortunately, this
results in an invalid DBus object path. Replace the dashes with an
underscore.

gtk/a11y/gtkatspicontext.c
gtk/a11y/gtkatspicontextprivate.h

index 31ef9a8842b812f43ee55d6abd78343aeedc5aed..4e0d205193bcb13d24e71cfed43742fcb34593b4 100644 (file)
@@ -150,13 +150,13 @@ gtk_at_spi_context_constructed (GObject *gobject)
   if (self->root == NULL)
     {
       self->root = gtk_at_spi_root_new (self->bus_address);
-      self->connection = gtk_at_spi_root_get_connection (self->root);
-
       g_object_set_data_full (G_OBJECT (display), "-gtk-atspi-root",
                               self->root,
                               g_object_unref);
     }
 
+  self->connection = gtk_at_spi_root_get_connection (self->root);
+
   /* We use the application's object path to build the path of each
    * accessible object exposed on the accessibility bus; the path is
    * also used to access the object cache
@@ -183,11 +183,23 @@ gtk_at_spi_context_constructed (GObject *gobject)
 
   self->context_path = g_strconcat (base_path, "/", uuid, NULL);
 
+  /* UUIDs use '-' as the separator, but that's not a valid character
+   * for a DBus object path
+   */
+  size_t path_len = strlen (self->context_path);
+  for (size_t i = 0; i < path_len; i++)
+    {
+      if (self->context_path[i] == '-')
+        self->context_path[i] = '_';
+    }
+
   GTK_NOTE (A11Y, g_message ("ATSPI context path: %s", self->context_path));
 
   g_free (base_path);
   g_free (uuid);
 
+  gtk_at_spi_context_register_object (self);
+
   G_OBJECT_CLASS (gtk_at_spi_context_parent_class)->constructed (gobject);
 }
 
@@ -391,3 +403,11 @@ gtk_at_spi_create_context (GtkAccessibleRole  accessible_role,
 
   return NULL;
 }
+
+const char *
+gtk_at_spi_context_get_context_path (GtkAtSpiContext *self)
+{
+  g_return_val_if_fail (GTK_IS_AT_SPI_CONTEXT (self), NULL);
+
+  return self->context_path;
+}
index d7457af0bab91d1aabd0f8464a87bca65eda0618..7c02efed7a32e7ff0ea796b072f93a6cca5ef8a1 100644 (file)
@@ -33,4 +33,7 @@ gtk_at_spi_create_context (GtkAccessibleRole  accessible_role,
                            GtkAccessible     *accessible,
                            GdkDisplay        *display);
 
+const char *
+gtk_at_spi_context_get_context_path (GtkAtSpiContext *self);
+
 G_END_DECLS